<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>watchEffect 的使用</title>
</head>
<body>
<div id="app">
    <h1>{{ count }}</h1>
    <button @click="buttonClicked">点击+1</button>
    <h1>{{ info }}</h1>
    <button @click="btnClicked">点击+1</button>


</div>
<script type="module">
    import {createApp, ref, watchEffect} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let count = ref(0)
            let info = ref("Hello, World！")
            // let abc = 1
            let abc = ref(1)

            function buttonClicked() {
                count.value += 1
            }


            function btnClicked() {
                info.value += "Hello, World!"
            }

            watchEffect(
                function () {
                    console.log("调用了监听函数 watchEffect");

                    // 直接使用变量没有效果
                    // let c = count
                    // 使用变量的.value 有效果
                    let c = count.value
                    // raw style 也是没有效果的
                    // let i = abc
                    let i = abc.value

                }
            )

            setInterval(
                function () {
                    // abc += 1
                    abc.value += 1
                },
                1000
            )

            return {
                count,
                buttonClicked,
                info,
                btnClicked,
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>